package com.haoting.mamba.player.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haoting.mamba.player.entity.vo.SortByVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoting.mamba.player.entity.PlayerBasicdateEntity;
import com.haoting.mamba.player.service.PlayerBasicdateService;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.R;



/**
 * 
 *
 * @author tanghao
 * @email 767417609@qq.com
 * @date 2021-03-14 20:47:39
 */
@RestController
@RequestMapping("player/playerbasicdate")
public class PlayerBasicdateController {
    @Autowired
    private PlayerBasicdateService playerBasicdateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = playerBasicdateService.queryPage(params);
        return R.ok().put("page", page);
    }

//    @GetMapping("/listVo/{current}/{size}")
//    public R listVo(@PathVariable("current") long current ,@PathVariable("size") long size){
//
//        Page<PlayerBasicdateEntityVo> basicdateEntityVoPage = new Page<>(current,size);
//
//        playerBasicdateService.getbasicVo(basicdateEntityVoPage);
//
//        long total = basicdateEntityVoPage.getTotal();
//        List<PlayerBasicdateEntityVo> records = basicdateEntityVoPage.getRecords();
//        return R.ok().put("records", records).put("total",total);
//    }

    @GetMapping("/getPlayerId/{id}")
    public R getPlayerId(@PathVariable("id") String id){
        PlayerBasicdateEntity playerBasicdateEntity = playerBasicdateService.getById(id);
        return R.ok().put("playerId",playerBasicdateEntity.getPlayerId());
    }


    @GetMapping("/getSortbyVO/{sortvo}")
    public R getSortbyVO(@PathVariable String sortvo){
        List<SortByVo> list = playerBasicdateService.getSortbyVO(sortvo);
        for (int i = 1; i <= list.size(); i++) {
            list.get(i-1).setSort(i);
            list.get(i-1).setName(list.get(i - 1).getName().split("-")[1]);
        }
        return R.ok().put("list",list);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		PlayerBasicdateEntity playerBasicdate = playerBasicdateService.getById(id);

        return R.ok().put("playerBasicdate", playerBasicdate);
    }
    @PostMapping("/infoByPlayerId/{id}")
    public R infoByPlayerId(@PathVariable("id") String id){
        QueryWrapper<PlayerBasicdateEntity> wrapper =new QueryWrapper<>();
        wrapper.eq("player_id",id)
        .eq("stage",0);
        PlayerBasicdateEntity one = playerBasicdateService.getOne(wrapper);
        return R.ok().put("playerBasicdate", one);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PlayerBasicdateEntity playerBasicdate){
		playerBasicdateService.save(playerBasicdate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PlayerBasicdateEntity playerBasicdate){
		playerBasicdateService.updateById(playerBasicdate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		playerBasicdateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
